package de.koller.oceanFramework.gl.util;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Frame {

	private Frame() {}
	
	public static void save( ParticleTexture texture, String file, int ax, int ay, int aw, int ah ) {
		BufferedImage b = new BufferedImage( aw, ah, 
				BufferedImage.TYPE_INT_ARGB );
		
		for( int x = ax; x < ax+aw; x++ )
			for( int y = ay; y < ay+ah; y++ )
				b.setRGB( x-ax, y-ay, texture.colorAt( x, y ) );
		
		try {
			ImageIO.write( b, "png", new File( file ) );
		} catch ( IOException ex ) {
			System.err.println( ex );
		}
	}
	
	public static void save( ParticleTexture texture, String file ) {
		Frame.save( texture, file, 0, 0, texture.getSize(), texture.getSize() );
	}
	
}
